import { ListPage } from "custom/index";
import { getEmployeeManagement, removeEmployeeManagement, sendResignationSms } from '../api'
import { onDutyStatusOptions, becomeRegularStatusOptions } from '../constant'
import { addDialog, editDialog, setPassDialog, authorizationDialog } from "./dialog"; './dialog'
import { ElMessage } from 'element-plus'

async function sendMessage({ props }) {
  const row = props.row || {}
  await sendResignationSms({ userId: row.userId })
  ElMessage.success('操作成功')
}

const page = new ListPage('EmployeeManagement');

page
  .api(getEmployeeManagement)
  .useSearch()
    .addInputItem('keyword', '员工姓名/花名/工号/手机号') 
    .addItem({ prop: 'name', label: '员工姓名' })
    .addItem({ prop: 'flowerName', label: '花名' })
    .addItem({ prop: 'no', label: '工号' })
    .addItem({ prop: 'mobile', label: '手机号' })
    .addDictSelect({ prop: 'deptNo', label: '部门' }, 'department')
    .end()
  .useTable()
    .addSelectionColumn()
    .useColumn('name').label('员工姓名').end()
    .addColumn({ prop: 'flowerName', label: '花名'})
    .addColumn({ prop: 'sex', label: '性别', sortable: 'custom'})
    .addColumn({ prop: 'mobile', label: '手机号码', minWidth: 120})
    .addColumn({ prop: 'no', label: '工号', sortable: 'custom'})
    .addColumn({ prop: 'companyName', label: '公司'})
    .addColumn({ prop: 'deptName', label: '部门', sortable: 'custom'})
    .addColumn({ prop: 'pestName', label: '岗位', sortable: 'custom'})
    .addColumn({ prop: 'entryDate', label: '入职日期', minWidth: 110, sortable: 'custom'})
    .addEnumColumn({ prop: 'onDutyStatus', label: '在职状态 ', sortable: 'custom', minWidth: 110}, onDutyStatusOptions)
    .addEnumColumn({ prop: 'becomeRegularStatus', label: '转正状态', sortable: 'custom', minWidth: 110}, becomeRegularStatusOptions)
    .addColumn({ prop: 'becomeRegulardDate', label: '转正时间', minWidth: 140})
    // .addColumn({ prop: 'sendDepartMsg', label: '离职短信', formatter(row) {
    //   return row.onDutyStatus ? '' : row.sendDepartMsg ? '已发送' : '未发送'
    // }})
    .end()
  .addPagination()
  .useAuthButton()
    .useItem('add').content('新增').primary().addRow(addDialog).end()
    .useItem('delete').content('删除').danger().removeRows(removeEmployeeManagement, selection => selection.map(i => i.userId)).end()
    .useItem('export').content('导出数据').exportExcel().end()
    .end()
  .useAuthColumn({ width: 140 })
    .useItem('')
      .formatter(row => {
        return row.onDutyStatus ? '' : row.sendDepartMsg ? '已发送' : '未发送'
      })
      .disabled(row => {
        return row.onDutyStatus ? true : row.sendDepartMsg ? true : false
      })
      .action(sendMessage)
      .end()
    .end()
  .useAuthColumn({ width: 230 })
    .useItem('auth').content('授权').editRow(authorizationDialog).end()
    .useItem('password').content('设置密码').editRow(setPassDialog).end()
    .useItem('export').content('编辑').editRow(editDialog).end()
    .useItem('delete').content('删除').removeRow(removeEmployeeManagement, row => [row.userId]).end()

export default page
